package com.gwnet.rider.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gwnet.common.core.domain.ResponseResult;
import com.gwnet.common.core.exception.base.BaseException;
import com.gwnet.common.satoken.utils.LoginHelper;
import com.gwnet.rider.domain.RiderWallet;
import com.gwnet.rider.service.RiderWalletService;
import com.gwnet.system.api.model.LoginUser;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 骑手钱包表 前端控制器
 * </p>
 *
 * @author WangLiang
 * @since 2024-08-06
 */
@RestController
@RequestMapping("/riderWallet")
public class RiderWalletController {

    private final RiderWalletService riderWalletService;


    public RiderWalletController(RiderWalletService riderWalletService) {
        this.riderWalletService = riderWalletService;
    }


    /**
     * 骑手获取自己的钱包信息
     * @return
     */
    @PostMapping("/view")
    public ResponseResult<RiderWallet> view(){
        LoginUser loginUser = LoginHelper.getLoginUser();
        LambdaQueryWrapper<RiderWallet> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RiderWallet::getRiderId,loginUser.getUserId());
        List<RiderWallet> list = riderWalletService.list(queryWrapper);
        if(list.size() > 0){
            return ResponseResult.success(list.get(0));
        }
        throw new BaseException("未查询您的账户信息");
    }


}

